home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / MPW181-5 / _SETUP.1 / synfilt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-21  |  2.3 KB  |  75 lines

  1. /*
  2.  *  @(#) synthesis_filter.h 1.8, last edit: 6/15/94 16:52:00
  3.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  4.  *  @(#) Berlin University of Technology
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #ifndef SYNTHESIS_FILTER_H
  22. #define SYNTHESIS_FILTER_H
  23.  
  24. #include "all.h"
  25. #include "obuffer.h"
  26.  
  27.  
  28. // A class for the synthesis filter bank:
  29. // This class does a fast downsampling from 32, 44.1 or 48 kHz to 8 kHz, if ULAW is defined.
  30. // Frequencies above 4 kHz are removed by ignoring higher subbands.
  31. class SynthesisFilter
  32. {
  33.   static const real d[512];
  34.   real v1[512], v2[512];
  35.   real *actual_v;            // v1 or v2
  36.   uint32 actual_write_pos;        // 0-15
  37.  
  38.   real     samples[32];            // 32 new subband samples
  39.  
  40.   uint32 channel;
  41.   real     scalefactor;
  42.   uint32 range_violations;
  43.   real     max_violation;
  44.   uint32 written_samples;
  45.  
  46.   void compute_new_v();
  47.   void compute_pcm_samples(Obuffer *buffer);
  48.  
  49.   // Clips the pcm sample so it will fit in 16 bits
  50.   inline int16 clip(int32 sample)
  51.   {
  52.       return ((int16) ((sample > 32767) ? 32767 :
  53.                     ((sample < -32768) ? -32768 : sample)));
  54.   }
  55.  
  56. public:
  57.     SynthesisFilter(uint32 channelnumber, real scalefactor = 32768.0);
  58.       // the scalefactor scales the calculated float pcm samples to short values
  59.       // (raw pcm samples are in [-1.0, 1.0], if no violations occur)
  60.  
  61.   void    input_sample (real sample, uint32 subbandnumber)
  62.   {
  63.      samples[subbandnumber] = sample;
  64.   };
  65.   void    calculate_pcm_samples(Obuffer *);
  66.     // calculate 32 PCM samples and put the into the Obuffer-object
  67.  
  68.   real     seconds_played(uint32 frequency)
  69.   {
  70.     return((real)written_samples / (real)frequency);
  71.   }
  72. };
  73.  
  74. #endif
  75.